<html>
 <head>
  <title>Test Page for PEJS</title>
  <script type="text/javascript" src="../src/interpreter.js"></script>
  <script type="text/javascript" src="../src/pejs_library.js"></script>
  <script type="text/javascript" src="test.js"></script>
  <script type="text/javascript">
    delayArray.sort();
    delayTest(delayArray);

    function delayTest(nameArray) {
      for (var i=0; i<nameArray.length; i++) {
        progName = nameArray[i];
        document.write("<script type=\"text/javascript\" src=\""+progName+".js\"></scr"+"ipt>");
      }
    }
  </script>
  <style type="text/css">
    body {
      font-family: Sans;
      font-size: 12pt;
    }
    td {
      font-size: 10pt;
      padding: 2pt;
      border: 1pt silver solid
    }
    td.no {
      text-align: right;
    }
    td.progName {
      font-family: Serif;
      width: 17em;
    }
    td.sourcejs {
      font-variant: small-caps;
      text-align: center;
    }
    td.sourcepy {
      font-variant: small-caps;
      text-align: center;
    }
    td.result {
      width: 6em;
      text-align: center;
    }
    td a {
      color: black;
      text-decoration: none;
    }
    td a:hover {
      color: blue;
      text-decoration: underline;
    }
    td.result a:hover {
      color: black;
      text-decoration: none;
    }
    div.banana {
      position: relative;
      left: 17em;
      top: -10em;
      z-index: 5;
      text-align: left;
    }
    img.db {
      width: 150px;
    }
  </style>
 </head>
 <body>
  <h1>PEJS Full Test</h1>
    <table><tr><th>No.</th><th>Test</th><th colspan="2">Source</th><th>Result</th></tr>
    <script type="text/javascript">
      var exceptions = new Array();
      var success = 0;
      var total = 0;

      function runTest(delayArr, withExceptions) {
        for (var i=0; i<delayArr.length; i++) {
          var progName = delayArr[i];
          document.write("<tr><td class='no'>"+(i+1)+"</td><td class='progName'><a href=\"testSingle.html?"+progName+"\">"+progName+"</a></td><td class=\"sourcejs\"><a href='"+progName+".js'>Js</a></td><td class=\"sourcepy\"><a href='"+progName+".py'>Py</a></td><td class='result'>");
          total++;
          if (withExceptions) {
            interpret(progName);
          } else {
            try {
              interpret(progName);
            } catch (exception) {
              document.write("<a title=\""+exception+"\">FAIL</a>");
              exceptions.push("<b>"+progName+"</b>: "+exception);
            }
          }
          document.write("</td><td class=\"single\"></td>");
        }
      }

      runTest(delayArray, false);

      var ary = document.getElementsByTagName("td");
      for(var i=0; i < ary.length; i++) {
        if(ary[i].className == "result") {
          if (ary[i].firstChild != null && ary[i].firstChild.nodeValue == "42") {
            success++;
            ary[i].firstChild.nodeValue = "OK";
            ary[i].style.background = "green";
          } else {
            ary[i].style.background = "red";
          }
        }
      }
    </script>
  </table><br/>
  <script type="text/javascript">
    document.write("<b>"+total+" tests run</b>: "+success+" succeeded, "+
                   (total-(success+exceptions.length))+" returned wrong result and "+
                   exceptions.length +" failed with an exception.<br/><br/>");

    if (success == total && success > 0)
      document.write("<div class='banana'><img class='db' src='dancing-banana.gif'/></div>");

    if (exceptions.length > 0) {
      document.write("<hr/><h3>Exceptions</h3>");
      for (var i=0; i<exceptions.length; i++) {
        document.write(exceptions[i]+"</br>");
      }
    }

  </script>
 </body>
</html>
